package manager.ikaraoke;

import java.util.ArrayList;
import java.util.Random;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class RoomListAdapter extends BaseAdapter{
	ArrayList<String> mItems = new ArrayList<String>();
	Context mContext;
	public RoomListAdapter(Context context, ArrayList<String> items) {
		// TODO Auto-generated constructor stub
		mContext = context;
		mItems = items;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mItems.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}
	 
	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder;
		if(convertView == null)
		{
			convertView = LayoutInflater.from(mContext).inflate(R.layout.room_list_item_view, null);
			viewHolder = new ViewHolder();
			viewHolder.mTvRoomName = (TextView)convertView.findViewById(R.id.tvRoomName);
			viewHolder.mIvRoomState = (ImageView)convertView.findViewById(R.id.ivRoomState);
			viewHolder.mTvCheckInTime = (TextView)convertView.findViewById(R.id.tvCheckInTime);
			convertView.setTag(viewHolder);
		}
		else
		{
			viewHolder = (ViewHolder)convertView.getTag();
		}
		Random r = new Random();
		if(r.nextInt()%2 == 0)
		{
			viewHolder.mIvRoomState.setImageResource( R.drawable.redlight);
		}
		else{
			viewHolder.mIvRoomState.setImageResource( R.drawable.greenlight);
		}
		viewHolder.mTvRoomName.setText("Room"+mItems.get(pos));
		return convertView;
	}
	
	class ViewHolder {
		TextView mTvRoomName;
		ImageView mIvRoomState;
		TextView mTvCheckInTime;
	}
}
